<template>
	<view class="content">
		<view class="header1">
			<view class="ipt-box">
				<input @input="searChange" v-model="searchIpt" type="text" value="" placeholder="请输入档案号"
					placeholder-class="plac-class" />
				<image src="/static/search1.png" mode="" @click="searNum"></image>
			</view>
			<view class="header1-right">
				<!-- <view @tap="clousText">取消</view> -->
				<easySelect class="easySelect" style="width:230rpx;height:100%;font-size: 28rpx;color: #fff;"
					:options="optionsData" ref="easySelect" :value="optionsDataText" @selectOne="optionsDatas">
				</easySelect>
			</view>

		</view>
		<!-- 图片 -->
		<!--  -->
		<view class="searShow" v-if="!mysearchIpt">
			<image src="/static/search.png" mode=""></image>
		</view>

		<cpimg ref="cpimg" @result="cpimgOk" @err="cpimgErr" :number="1" :fixOrientation="true" :size="500"
			:maxWidth="800" :ql="0.7" type="url" />

	</view>
</template>

<script>
	import cpimg from "@/components/cpimg/cpimg.vue"
	import easySelect from '@/components/easy-select/easy-select'
	export default {
		components: {
			easySelect,
			cpimg
		},
		data() {
			return {
				optionsData: [{
						id: 2,
						label: '居民用户'
					},
					{
						id: 1,
						label: '工商业用户'
					},
					{
						id: 3,
						label: '安检记录表'
					}
				],
				optionsDataText: '',
				optionsDataId: '',
				index: 0,
				ret: '',
				mysearchIpt: false,
				searchIpt: '',
				searchIpts: '',
				flag: true,
				token: '',
				last_check: {},
				user_info: {},
				textNumber: 0,
				// 品牌id
				brandId: '',
				// 功率id
				powerId: '',
				// 备注
				autoText: '',
				// 气表底数
				meter_base_num: '',
				// 默认显示品牌名
				brandName: '',
				// 默认显示功率
				powerName: '',
				// 气表照片地址
				fileImg1: '',
				img1: '',

				fileImg2: [],
				img2: [],

				fileImg3: [],
				img3: [],
				fileImg4: '',
				img4: '',
				// 是否安检
				isChecked: true,
				isCheckedNum: '',
				// 是否签收
				isChecked1: true,
				isCheckedNum1: '',
				// 是否派发
				isChecked2: true,
				isCheckedNum2: '',
				showRecord: true,
				marginBotton1: 100 + 'rpx',
				danger_id: ''
			}
		},
		onShow() {
			this.token = uni.getStorageSync('token')
		},
		onLoad() {
			this.optionsDataText = this.optionsData[0].label
			this.optionsDataId = this.optionsData[0].id
		},
		methods: {
			optionsDatas(option) {
				let that = this
				that.optionsDataText = option.label
				that.optionsDataId = option.id
				if(option.id==3){
					// this.$navTo('./security')
					this.$navTo('/pagesB/rithcheck/meterList')
				}
			},
			PickerChange(e) {
				this.index = e.detail.value
			},
			brandChange(option) {
				console.log(option)
				this.user_info.brand_name = option.label
				this.options.forEach(item => {
					if (item.label == this.user_info.brand_name) {
						this.brandId = item.id
					}
				})
			},
			powerChange(option) {
				this.user_info.power_name = option.label
				this.options1.forEach(item => {
					if (item.label == this.user_info.power_name) {
						this.powerId = item.id
					}
				})
			},
			// 是否安检
			// switch1Change(e) {
			// 	let that = this
			// 	that.isChecked = !that.isChecked
			// },
			//图片删除
			updetail(type, index) {
				this.img1 = ''
			},
			updetail2(index) {
				this.img2.splice(index, 1)
			},
			updetail3(index) {
				this.img3.splice(index, 1)
			},
			updetail4(index) {
				this.img4 = ""
			},
			//图片预览
			seeimg(img) {
				uni.previewImage({
					urls: [img],
					longPressActions: {
						itemList: [],
						success: function(data) {
							console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
						},
						fail: function(err) {
							console.log(err.errMsg);
						}
					}
				});
			},

			// 选择气表照片

			changeImg(ret) {
				var that = this;
				that.ret = ret
				that.$refs.cpimg._changImg()

			},
			cpimgOk(file) {
				let that = this
				var ret = that.ret
				uni.showLoading({
					title: '上传中...'
				})
				uni.uploadFile({
					url: that.$api + '/common/upload',
					filePath: file[0],
					name: 'file',
					formData: {
						token: that.token
					},
					success(res1) {
						let dataPath = JSON.parse(res1.data)
						if (dataPath.code == 1) {
							if (ret == '燃气表') {
								that.fileImg1 = dataPath.data.url
								that.img1 = file[0]
								// console.log(111)
							}
							if (ret == '燃气火点') {
								that.fileImg2.push(dataPath.data.url)
								that.img2.push(file[0])
							}
							if (ret == '资料') {
								that.fileImg3.push(dataPath.data.url)
								that.img3.push(file[0])
							}
							if (ret == '其他') {
								that.fileImg4 = dataPath.data.url
								that.img4 = file[0]
							}
						}
						uni.hideLoading()
					},
					fail: () => {
						uni.hideLoading()
						uni.showToast({
							title: '上传失败'
						})
					}
				});


			},

			cpimgErr(e) {
				uni.showToast({
					title: '上传失败',
					icon: 'none'
				})
				console.log(e)
			},

			textChange(e) {
				if (e.detail.cursor >= 200) {
					uni.showToast({
						title: '最多可以输入200个字',
						icon: 'none'
					})
				}
				this.textNumber = e.detail.cursor
			},
			// 提交保存
			userPost() {

				console.log(this.last_check.staff_name)

				let that = this
				that.options.forEach(item => {
					if (item.label == that.user_info.brand_name) {
						that.brandId = item.id
					}
				})
				that.options1.forEach(item => {
					if (item.label == that.user_info.power_name) {
						that.powerId = item.id
					}
				})
				if (that.brandId == '') {
					uni.showToast({
						title: '请选择品牌',
						icon: 'none'
					})
					return
				}
				if (that.powerId == '') {
					uni.showToast({
						title: '请选择实际功率',
						icon: 'none'
					})
					return
				}
				if (that.img1 == '') {
					uni.showToast({
						title: '请上传燃气表照片',
						icon: 'none'
					})
					return
				}
				if (that.img2.length < 2) {
					uni.showToast({
						title: '请上传2张燃气火点照片',
						icon: 'none'
					})
					return
				}
				if (that.img3.length < 4) {
					uni.showToast({
						title: '请上传4张资料照片',
						icon: 'none'
					})
					return
				}
				if (that.img4 == '') {
					uni.showToast({
						title: '请上传其他照片',
						icon: 'none'
					})
					return
				}
				if (that.isChecked == false) {
					that.isCheckedNum = '0'
				} else {
					that.isCheckedNum = '1'
				}
				if (that.isChecked1 == false) {
					that.isCheckedNum1 = '0'
				} else {
					that.isCheckedNum1 = '1'
				}
				if (that.isChecked2 == false) {
					that.isCheckedNum2 = '0'
				} else {
					that.isCheckedNum2 = '1'
				}

				var imgs2 = ''
				var imgs3 = ''
				that.fileImg2.forEach(item => {
					imgs2 += item + ','
				})
				that.fileImg3.forEach(item => {
					imgs3 += item + ','
				})
				that.$request.request({
					url: '/staff/check_submit',
					method: 'POST',
					data: {
						member_id: that.user_info.id,
						token: that.token,
						brand: that.brandId,
						power: that.powerId,
						meter_base_num: that.user_info.meter_base_num,
						qibiao_img: that.fileImg1,
						dianhuo_img: imgs2,
						qimi_img: imgs3,
						success_img: that.fileImg4,
						danger_id: this.danger_id,
						is_receive: that.isCheckedNum,
						is_safe: that.isCheckedNum1,
						mark: that.autoText
					}
				}).then(res => {
					if (res.data.code == 1) {
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						})
						that.flag = true
						that.searchIpt = ''
					}
				})
			},
			searNum() {

				let that = this
				if (that.searchIpt == '') {
					this.$showToast('请输入要搜索的编号')
					return
				}
				if (this.optionsDataId == 2) {
					uni.request({
						url: that.$api + 'staff/user_search',
						method: 'POST',
						header: {
							token: that.token,
							'content-type':'application/x-www-form-urlencoded'
						},
						data: {
							token: that.token,
							meter_num: that.searchIpt
						},
						success: (res) => {
							if (res.data.code == 1) {
								this.$navTo('./resident?token=' +
									that.token + '&meter_num=' + that.searchIpt)
							} else {
								that.$showToast(res.data.msg)
								that.flag = true
								that.searchIpt = ''
							}
						}
					})
				}
				if (this.optionsDataId == 1) {
					uni.request({
						url: that.$url + 'staff.business/searchUser',
						method: 'POST',
						header: {
							token: that.token,
						},
						data: {
							token: that.token,
							meter_num: that.searchIpt
						},
						success: (res) => {
							if (res.data.code == 1) {
								this.$navTo('./business?token=' +
									that.token + '&meter_num=' + that.searchIpt)
							} else {
								that.$showToast(res.data.msg)
								that.flag = true
								that.searchIpt = ''
							}
						}
					})
				}

				// if (this.optionsDataId == 3) {
				// 	uni.request({
				// 		url: that.$url + 'staff.Inspect/searchUser',
				// 		method: 'POST',
				// 		header: {
				// 			token: that.token,
				// 		},
				// 		data: {
				// 			token: that.token,
				// 			meter_num: that.searchIpt
				// 		},
				// 		success: (res) => {
				// 			if (res.data.code == 1) {
				// 				this.$navTo('./security?token=' +
				// 					that.token + '&meter_num=' + that.searchIpt)
				// 			} else {
				// 				that.$showToast(res.data.msg)
				// 				that.flag = true
				// 				that.searchIpt = ''
				// 			}
				// 		}
				// 	})
				// }


			},
			searChange(e) {
				// console.log(e.detail)
				if (e.detail.value == '') {
					this.flag = false
				}
			},
			clousText() {
				this.flag = true
				this.searchIpt = ''
			},
			danger() {

				if (this.img1 != '') {
					uni.setStorage({
						key: 'img1',
						data: this.img1
					})
				}

				if (this.img2.length > 0) {
					uni.setStorage({
						key: 'img2',
						data: this.img2
					})
				}

				if (this.img3.length > 0) {
					uni.setStorage({
						key: 'img3',
						data: this.img3
					})
				}

				if (this.img4 != '') {
					uni.setStorage({
						key: 'img4',
						data: this.img4
					})
				}

				if (this.autoText != '') {
					uni.setStorage({
						key: 'bztext',
						data: this.autoText
					})
				}

				uni.navigateTo({
					url: '../securityCheck/dangerReport?id=' + this.last_check.member_id + '&type=' + '5' +
						'&socont=' + this.searchIpt
				})

			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		background: #F1F1F1;

		.header {
			display: flex;
			justify-content: space-between;
			align-items: center;
			// padding: 30rpx 30rpx;
			background-color: #fff;

			.header-right {
				display: flex;
				align-items: center;
				font-size: 24rpx;
				color: #333;
				margin-right: 20rpx;

				image {
					width: 32rpx;
					height: 32rpx;
					margin-right: 10rpx;
				}
			}
		}

		.header1 {
			display: flex;
			align-items: center;
			box-sizing: border-box;
			height: 80rpx;
			width: 100%;
			background-color: #003690;
			padding: 0 30rpx;

			.ipt-box {
				display: flex;
				justify-content: space-between;
				align-items: center;
				box-sizing: border-box;
				padding: 0 20rpx;
				width: 450rpx;
				height: 52rpx;
				background-color: #fff;
				border-radius: 24rpx;

				image {
					width: 32rpx;
					height: 32rpx;
				}
			}

			.header1-right {
				display: flex;
				align-items: center;
				font-size: 28rpx;
				color: #E2ECFB;
				flex: 1;
				justify-content: center;

				image {
					width: 36rpx;
					height: 36rpx;
				}
			}
		}

		.searShow {
			width: 360rpx;
			height: 254rpx;
			position: fixed;
			top: 50%;
			left: 50%;
			transform: translate(-50%, -50%);

			image {
				width: 100%;
				height: 100%;
			}
		}

		.dataCont {
			padding-top: 12rpx;
			padding-left: 42rpx;
			padding-right: 30rpx;

			.searTitle {
				font-size: 32rpx;
				font-weight: 600;
				text-align: left;
				color: #333333;
			}

			.searResult {
				display: flex;
				justify-content: space-between;

				.resText {
					font-size: 32rpx;
					font-weight: 400;
					text-align: left;
					color: #777777;
				}

				image {
					width: 36rpx;
					height: 36rpx;
				}
			}
		}

		.ipts {
			background-color: #fff;
			margin-bottom: 20rpx;
		}

		.info-item {
			box-sizing: border-box;
			display: flex;
			align-items: center;
			justify-content: space-between;
			// height: 72rpx;
			width: 100%;
			padding: 10rpx 30rpx;
			background-color: #fff;
			font-size: 24rpx;
			color: #333;

			image {
				width: 32rpx;
				height: 32rpx;
			}

			input {
				flex: 1;
				text-align: right;
			}

			.dot {
				width: 8rpx;
				height: 8rpx;
				background-color: #003690;
				border-radius: 50%;
				margin-right: 10rpx;
			}

			.danger-img {
				position: relative;

				.updeletes {
					position: absolute;
					top: -20rpx;
					right: -20rpx;
					width: 40rpx;
					height: 40rpx;
					z-index: 88;

					image {
						width: 100%;
						height: 100%;
					}
				}
			}

			.danger-img-box {
				display: flex;

				.danger-img {
					width: 75rpx;
					height: 75rpx;
					// border: 2rpx dashed #eee;
					margin-right: 10rpx;


					image {
						width: 100%;
						height: 100%;
					}
				}
			}

			.danger-img-box2 {
				display: flex;

				.danger-img {
					width: 75rpx;
					height: 75rpx;
					// border: 2rpx dashed #eee;
					margin-right: 10rpx;

					image {
						width: 100%;
						height: 100%;
						opacity: 1;
					}
				}
			}

			.info-item-left {
				display: flex;
				align-items: center;
				font-size: 32rpx;
			}
		}

		.hengxian {
			width: 700rpx;
			height: 2rpx;
			background-color: #eee;
			margin: 20rpx auto;
		}

		.place-class {
			font-size: 26rpx;
			color: #999;
		}

		.btn {
			width: 646rpx;
			height: 80rpx;
			margin: 74rpx auto;
			text-align: center;
			line-height: 80rpx;
			border-radius: 40rpx;
			background-image: linear-gradient(to bottom, #2366D5, #001B48);
			font-size: 32rpx;
			color: #E5EFFE;
		}

		.btns {
			position: fixed;
			bottom: 0;
			display: flex;
			width: 100%;
			z-index: 333;

			.btn1 {
				width: 50%;
				height: 96rpx;
				line-height: 96rpx;
				text-align: center;
				font-size: 24rpx;
			}

			.consel {
				background-color: #e9e9e9;
				color: #777;
			}

			.save {
				background-color: #003690;
				color: #fff;
			}
		}

		.btn:active {
			background: rgba(0, 0, 0, 0.4);
		}

		.zhanwei {
			height: 250rpx;
		}

		.record {
			display: flex;
			align-items: center;
			color: #003690;
			font-size: 32rpx;
			padding: 20rpx 0;

			// margin-top: 20rpx;
			image {
				width: 32rpx;
				height: 32rpx;
				margin: 0 20rpx 0 30rpx;
			}
		}

		.record-item {
			display: flex;
			justify-content: space-between;
			padding: 10rpx 30rpx;
			border-bottom: 2rpx solid #eee;

			.record-item-left {
				display: flex;
				align-items: center;

				.shu {
					width: 8rpx;
					height: 28rpx;
					background-color: #003690;
					border-radius: 8rpx;
				}

				.title {
					font-size: 32rpx;
					color: #333;
					font-weight: 500;
					margin: 0 10rpx;
				}

				.time {
					font-size: 24rpx;
					color: #777;
				}
			}

			.record-item-right {
				display: flex;
				align-items: center;

				.dianhua {
					width: 28rpx;
					height: 28rpx;
				}

				.zhankai {
					width: 36rpx;
					height: 36rpx;
				}

				.title {
					font-size: 32rpx;
					color: #555;
					font-weight: 500;
					margin: 0 10rpx;
				}
			}
		}

		.supplement {
			margin: 20rpx 24rpx;
			background-color: #fff;
			position: relative;
			overflow: hidden;

			.explain {
				.textArea {
					min-height: 142rpx;
					padding: 14rpx 30rpx;
					font-size: 32rpx;
					text-align: left;
					color: rgba(187, 187, 187, 0.84);
				}
			}

			.suppBottom {
				.danger-img {
					position: relative;
					margin-left: 50rpx;
					margin-bottom: 0rpx;
					width: 68rpx;
					height: 68rpx;
					float: left;

					image {
						width: 36rpx;
						height: 36rpx;
						position: absolute;
						left: 50%;
						top: 50%;
						transform: translate(-50%, -50%);
					}
				}

				.num {
					float: right;
					margin-right: 26rpx;
				}
			}
		}
	}
</style>
